package com.xc.h05.controller.weichen;

import com.github.pagehelper.PageInfo;
import com.xc.h05.entity.Heartmark;
import com.xc.h05.service.weichen.HeartmarkService;
import com.xc.h05.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
// 心理测评
@RestController
@RequestMapping("/heartmark")
public class HeartmarkController {
    @Autowired
    private HeartmarkService heartmarkService;
    //测试 查询所有
    @GetMapping("/findAll")
    public R findAll(){
        List<Heartmark> list = heartmarkService.findAll();
        return R.ok(list);
    }

    // 根据**分页查询
    @GetMapping("/findByPage")
    public R findByPage(int pageNum,int pageSize, Heartmark heartmark){
        PageInfo<Heartmark> pageInfo = heartmarkService.findByPage(pageNum,pageSize,heartmark);
        return R.ok(pageInfo);
    }
    //根据id查询
    @GetMapping("/findById")
    public R findById(long id){
        Heartmark heartmark = heartmarkService.findById(id);
        return R.ok(heartmark);
    }

    //增加
    @PostMapping("/add")
    public R add(@RequestBody Heartmark heartmark){
        int add = heartmarkService.add(heartmark);
        if (add!=0){
            return R.ok(add);
        }else {
            return R.fail("添加失败");
        }
    }
    //删除
    @DeleteMapping( "/delete/{id}" )
    public R delete(@PathVariable("id") int id){
        int delete = heartmarkService.delete(id);
        if (delete!=0){
            return R.ok(delete);
        }else {
            return R.fail("删除失败");
        }
    }
    //批量删除
    @PostMapping("/deletes")
    public R deletes(@RequestBody List<Integer> list){
        int deletes = heartmarkService.deletes(list);
        System.out.println(list);
        if (deletes!=0){
            return R.ok(deletes);
        }else {
            return R.fail("删除失败");
        }
    }
    //修改
    @PutMapping("/update")
    public R update(@RequestBody Heartmark heartmark){
        int update = heartmarkService.update(heartmark);
        if (update!=0){
            return R.ok(heartmark);
        }else {
            return R.fail("修改失败");
        }
    }

}
